<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :md="6" :sm="8">
            <a-form-item label="数据来源" :label-col="{ span: 6 }" :wrapper-col="{ span: 16 }">
                <j-dict-select-tag style="width: 260px" v-model="queryParam.dataSource" placeholder="请选择订单类型"
                                   dictCode="dataSourceDaily"/>
            </a-form-item>
          </a-col>
          <a-col :md="18" :sm="16">
            <span class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="showOrClose" icon="search" style='margin-left: 10px;'>高级查询</a-button>
            </span>
                    </a-col>
                </a-row>
            </a-form>
        </div>
        <a-row v-if="show" style="padding-top: 0px">
            <a-col :md="6" :sm="8">
                <a-form-item label="供应商名称" :label-col="{ span: 6 }" :wrapper-col="{ span: 15 }">
                  <j-dict-select-tag style="width: 260px" v-model="queryParam.supplierCode" placeholder="请选择供应商"
                                     dictCode="supplierName"/>
                </a-form-item>
            </a-col>
            <a-col :md="6" :sm="8">
                <a-form-item label="订单ID" :label-col="{ span: 6 }" :wrapper-col="{ span: 16 }">
                    <a-input placeholder="订单ID" v-model="queryParam.ID"/>
                </a-form-item>
            </a-col>
            <a-col :md="6" :sm="8">
                <a-form-item label="种类编码" :label-col="{ span: 6 }" :wrapper-col="{ span: 16 }">
                    <j-dict-select-tag style="width: 260px" v-model="queryParam.subclassCode" placeholder="请选择种类"
                                       dictCode="subclassCode"/>
                </a-form-item>
            </a-col>
            <a-col :md="6" :sm="8">
                <a-form-item label="操作类型" :label-col="{ span: 6 }" :wrapper-col="{ span: 16 }">
                    <a-input placeholder="操作类型" v-model="queryParam.operationType"/>
                </a-form-item>
            </a-col>
            <a-col :md="6" :sm="8">
                <a-form-item label="操作日期(始)" :label-col="{ span: 6 }" :wrapper-col="{ span: 16 }">
                    <a-date-picker valueFormat="YYYY-MM-DD" v-model="queryParam.operationStartDate"></a-date-picker>
                </a-form-item>
            </a-col>
            <a-col :md="6" :sm="8">
                <a-form-item label="操作日期(止)" :label-col="{ span: 6 }" :wrapper-col="{ span: 16 }">
                    <a-date-picker valueFormat="YYYY-MM-DD" v-model="queryParam.operationEndDate"></a-date-picker>
                </a-form-item>
            </a-col>
            <a-col :md="6" :sm="8">
                <a-form-item label="上级ID" :label-col="{ span: 6 }" :wrapper-col="{ span: 16 }">
                    <a-input placeholder="上级ID" v-model="queryParam.linkPUID"/>
                </a-form-item>
            </a-col>
        </a-row>

        <!-- table区域-begin -->
        <div>
            <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
                <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a style="font-weight: 600">{{
                selectedRowKeys.length }}</a>项
                <a style="margin-left: 24px" @click="onClearSelected">清空</a>
            </div>

            <a-table
                    :scroll="{ x: 1500}"
                    ref="table"
                    size="middle"
                    bordered
                    rowKey="index"
                    :columns="columns"
                    :dataSource="dataSource"
                    :pagination="ipagination"
                    :loading="loading"
                    :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
                    @change="handleTableChange">

        <span slot="action" slot-scope="text, record">
          <a @click="toDataDetailedInfo(record)">详情</a>
          <a-divider type="vertical"/>
          <a @click="toDd(record)">关联订单</a>
        </span>
            </a-table>
        </div>
        <!--    <EipSalesOrderDetail v-if="showSalesOrderDetail" ref="EipSalesOrderDetail" :dataSourceDetail="dataSourceDetail"-->
        <!--                         @close="closeDetail"/>-->
        <eipDataDetailedInfo-modal ref="modalForm" @ok="modalFormOk"></eipDataDetailedInfo-modal>
        <eipProductionOrder-detail v-if="showProductionOrderDetail" ref="EipProductionOrderDetail"
                                   :dataSourceDetail="dataSourceDetail" @close="closeDetail"/>
        <eipWorkOrder-detail v-if="showWorkOrderDetail" ref="EipWorkOrderDetail"
                             :dataSourceDetail="dataSourceDetail" @close="closeDetail"/>
        <eipOperation-detail v-if="showOperationDetail" ref="EipOperationDetail" :dataSourceDetail="dataSourceDetail"
                             @close="closeDetail"/>
    </a-card>
</template>

<script>

    import {JeecgListMixin} from '@/mixins/JeecgListMixin'
    import EipDataDetailedInfoModal from './modules/EipDataDetailedInfoModal'
    import EipSalesOrderDetail from '../../sjshjy/EipSalesOrder/modules/EipSalesOrderDetail'
    import EipProductionOrderDetail from '../../sjshjy/EipProductionOrder/modules/EipProductionOrderDetail'
    import EipWorkOrderDetail from '../../sjshjy/EipWorkOrder/modules/EipWorkOrderDetail'
    import EipOperationDetail from '../../sjshjy/EipOperation/modules/EipOperationDetail'
    import EipPurchaseDetail from '../../dd/EipPurchaseOrder/modules/EipPurchaseOrderDetail'
    import {deleteAction, postAction, getAction, downFile} from '@/api/manage'

    export default {
        name: 'EipDataDetailedInfoList',
        mixins: [JeecgListMixin],
        components: {
            EipDataDetailedInfoModal,
            EipProductionOrderDetail,
            EipWorkOrderDetail,
            EipOperationDetail,
            EipSalesOrderDetail,
            EipPurchaseDetail
        },
        data() {
            return {
                flag: true,
                description: 'eip_data_detailed_info管理页面',
                detailedInformation: {},
                dataSourceDailyDict: {},
                subclassCodeDict: {},
                operationStartDate: null,
                operationEndDate: null,
                show: false,                      //高级查询
                visible: false,                   //详情是否打开
                showProductionOrderDetail: false, //
                showWorkOrderDetail: false,       //详情
                showOperationDetail: false,       //详情
                showSalesOrderDetail: false,       //详情
                showPurchaseOrderDetail: false,    //详情
                dataSource: [],                   //列表数据
                dataSourceDetail: {},             //详细数据
                modalWidth: '75%',
                tstyle: {
                    'height': '500px',
                    'overflow': 'auto'
                },
                loading: false,
                confirmLoading: false,
                // 表头
                columns: [
                    {
                        title: '供应商名称',
                        align: 'center',
                        dataIndex: 'supplierName'
                    },
                    {
                        title: '数据来源',
                        align: 'center',
                        dataIndex: 'dataSource'
                    },
                    {
                        title: '订单ID',
                        align: 'center',
                        dataIndex: 'id'
                    },
                    {
                        title: '操作类型(同步/推送)',
                        align: 'center',
                        dataIndex: 'operationType'
                    },
                    {
                        title: '操作人员',
                        align: 'center',
                        dataIndex: 'userID'
                    },
                    {
                        title: '操作日期',
                        align: 'center',
                        dataIndex: 'operationDate',
                        customRender: function (text) {
                            return !text ? '' : (text.length > 10 ? text.substr(0, 10) : text)
                        }
                    },
                    {
                        title: '批注(错误信息)',
                        align: 'center',
                        dataIndex: 'comment'
                    },
                    {
                        title: '操作',
                        dataIndex: 'action',
                        align: 'center',
                        scopedSlots: {customRender: 'action'}
                    }
                ],
                url: {
                    list: '/eipDataDetailedInfo/selectForList',
                    dictSourceUrl: '/sys/dict/getDicByCode'
                },
                dictOptions: {}
            }
        },
        computed: {
            importExcelUrl: function () {
                return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`
            }
        },
        methods: {
            loadDataSourceDailyDict() {
                let dictParams = {'dictCode': 'dataSourceDaily'}
                getAction(this.url.dictSourceUrl, dictParams).then((res) => {
                    this.dataSourceDailyDict = res
                })
            },
            loadSubClassCodeDict() {
                let dictParams = {'dictCode': 'subclassCode'}
                getAction(this.url.dictSourceUrl, dictParams).then((res) => {
                    this.subclassCodeDict = res
                })
            },
            showOrClose() {//高级查询是否展开
                this.show = !this.show
            },
            closeDetail() {//详情
                this.showProductionOrderDetail = false
                this.showWorkOrderDetail = false
                this.showOperationDetail = false
                this.showSalesOrderDetail = false
                this.showPurchaseOrderDetail =false
            },
            toDataDetailedInfo(record) {
                this.visible = true
                if(record.dataSource === '采购订单') {
                    this.showPurchaseOrderDetail =true
                    let purchaseOrderDetail = JSON.parse(record.detailedInformation)
                    this.dataSourceDetail = purchaseOrderDetail
                }
                if (record.dataSource === '销售订单') {
                    this.showSalesOrderDetail = true
                    let salesOrderDetail = JSON.parse(record.detailedInformation)
                    this.dataSourceDetail = salesOrderDetail
                }
                if (record.dataSource === '生产订单') {
                    this.showProductionOrderDetail = true
                    let productionOrder = JSON.parse(record.detailedInformation)
                    console.log(typeof productionOrder)
                    this.dataSourceDetail = productionOrder
                }
                if (record.dataSource === '工单') {
                    this.showWorkOrderDetail = true
                    let workOrder = JSON.parse(record.detailedInformation)
                    console.log(typeof workOrder)
                    this.dataSourceDetail = workOrder
                }
                if (record.dataSource === '报工') {
                    this.showOperationDetail = true
                    let operation = JSON.parse(record.detailedInformation)
                    console.log(typeof operation)
                    this.dataSourceDetail = operation
                }
            },
            toDd(record) {
                localStorage.setItem('puid', JSON.parse(record.detailedInformation).puid)
                if("采购订单" === record.dataSource){
                    localStorage.setItem('poNo',record.id)
                    this.$router.push({path: '/eipPurchaseOrder/list'})
                }
                if ('销售订单' === record.dataSource) {
                    localStorage.setItem('soNo', record.id)
                    this.$router.push({path: '/eipSalesOrder/list'})
                }
                if ('生产订单' === record.dataSource) {
                    localStorage.setItem('ipoNo', record.id)
                    this.$router.push({path: '/eipProductionOrder/list'})
                }
                if ('工单' === record.dataSource) {
                    localStorage.setItem('woNo', record.id)
                    this.$router.push({path: '/eipWorkOrder/list'})
                }
                if ('报工' === record.dataSource) {
                    localStorage.setItem('insideNo', JSON.parse(record.detailedInformation).insideNo)
                    this.$router.push({path: '/eipOperation/list'})
                }
            }
            , loadData(arg) {
                if (this.flag) {
                    this.loadDataSourceDailyDict()
                    this.loadSubClassCodeDict()
                    this.flag = false
                }
                if (arg === 1) {
                    this.ipagination.current = 1
                }
                let params = {'pageNo': this.ipagination.current, 'pageSize': this.ipagination.pageSize}
                let linkPUID = localStorage.getItem('linkPUID')
                if (linkPUID != null) {
                    this.queryParam.linkPUID = linkPUID
                    params['linkPUID'] = linkPUID
                } else {
                    params = this.getQueryParams()//查询条件
                }
                this.loading = true
                getAction(this.url.list, params).then((res) => {
                    if (res.success) {
                        this.dataSource = res.result.records
                        this.dataSource.forEach(item => {
                            item.dataSource = this.dataSourceDailyDict[item.dataSource]
                            item.subclassCode = this.subclassCodeDict[item.subclassCode]
                        })
                        this.ipagination.total = res.result.total
                    }
                    if (res.code === 510) {
                        this.$message.warning(res.message)
                    }
                    this.loading = false
                })
                localStorage.removeItem('linkPUID')
            }
        }
    }
</script>
<style scoped>
    @import '~@assets/less/common.less'
</style>
